var Hover = new Vue({
    el: '#Hover',
    data: {
        List: [],
        state: false
    },
    mounted() {
        if (window.top != window.self) return;
        var Data = layui.data('Hover');
        if (Data.state != undefined) {
            this.state = Data.state;
            this.List = Data.List;
            $("#Hover").show();
        }
        this.AjaxList();
    },
    methods: {
        AjaxList() {
            let _this = this;
            $.ajax({
                type: 'post',
                url: 'ajax.php?act=HoverList',
                dataType: 'json',
                success: function (res) {
                    if (res.code >= 0) {
                        layui.data('Hover', {
                            key: 'List',
                            value: res.data
                        });
                        _this.List = res.data;
                        $("#Hover").show();
                    } else {
                        layui.data('Hover', {
                            key: 'List',
                            value: []
                        });
                        _this.List = [];
                    }
                }
            });
        },
        switchs() {
            if (this.state == false) {
                layui.data('Hover', {
                    key: 'state',
                    value: true
                });
                this.state = true;
            } else {
                layui.data('Hover', {
                    key: 'state',
                    value: false
                });
                this.state = false;
            }
        },
        Open(id, name) {
            let _this = this;
            let is = layer.msg('插件[ ' + name + ' ]模板载入中，请稍后...', {icon: 16, time: 9999999});
            $.ajax({
                type: "POST",
                url: 'ajax.php?act=AppId',
                data: {
                    id: id
                },
                dataType: "json",
                success: function (res) {
                    layer.close(is);
                    if (res.code >= 0) {
                        if (document.body.clientWidth > 750) {
                            area = ['90%', '90%'];
                        } else area = ['96%', '96%'];
                        layer.open({
                            type: 2,
                            area: area,
                            title: name,
                            content: 'ajax.php?act=app_view&id=' + id + '&path=index&t=' + res.id,
                        });
                    } else layer.msg(res.msg);
                },
                error: function () {
                    layer.msg('服务器异常！');
                }
            });
        }
    }
});

layui.use('flow', function () {
    var flow = layui.flow;
    flow.lazyimg();
});

function data_header() {
    var datar = layui.data('header_data');
    if (datar.data != undefined) {
        var headertime = layui.data('headertime');
        var mis = headertime.time - 1;
        if (mis > 0) {
            header_datas(JSON.parse(datar.data));
            layui.data('headertime', {
                key: 'time',
                value: mis
            });
            return false;
        }
    }
    $.ajax({
        type: 'post',
        url: 'ajax.php?act=data_header',
        dataType: 'json',
        success: function (data) {
            var datas = JSON.stringify(data);
            layui.data('header_data', {
                key: 'data',
                value: datas
            });
            /**
             * 18次一轮询，提高网站速度
             */
            layui.data('headertime', {
                key: 'time',
                value: 38
            });

            header_datas(data);
        }
    });
}

function header_datas(data) {
    if (data.code == 1) {
        $('#code_img').attr('href', data.weix_img);
        $('.group').attr('href', data.TheOfficialGroup);
        $('#head_image').attr('src', data.image);
        $('#header_name').text(data.name);
        var content = '';
        for (let a = 0; a < data.notice.length; a++) {
            content +=
                '<a href="?message=' +
                data.notice[a]['id'] +
                '" class="dropdown-item notify-item">\n' +
                '          <div class="notify-icon bg-primary">\n' +
                '             <i class="mdi mdi-comment-account-outline"></i>\n' +
                '          </div>\n' +
                '          <p class="notify-details">' +
                data.notice[a]['title'] +
                '\n' +
                '                <small class="text-muted">' +
                data.notice[a]['date'] +
                '</small>\n' +
                '          </p>\n' +
                '       </a>';
        }
        $('#message').html(content);
    } else if (data.code == -2) {
        setTimeout(function () {
            index_update();
        }, 1000);
    } else {
        layui.data('headertime', {
            key: 'time',
            value: 0
        });
        layer.msg(data.msg, {
            icon: 4
        });
    }
}

data_header();
